using System;
using HCP.Responses;
using HCP.SimpleJSON;
using UnityEngine;
using UnityEngine.EventSystems;

namespace HCP.Requests
{
	public class TouchLongClickElement : JobRequest
	{
		public TouchLongClickElement(JSONClass json) : base(json)
		{
			this.m_endTime = 0f;
			this.m_startTime = 0f;
		}

		public string Id
		{
			get
			{
				return base.Data["elementId"];
			}
		}

		public float X
		{
			get
			{
				return base.Data["x"].AsFloat;
			}
		}

		public float Y
		{
			get
			{
				return base.Data["y"].AsFloat;
			}
		}

		public float Duration
		{
			get
			{
				return base.Data["duration"].AsFloat;
			}
		}

		protected TouchLongClickElement.EState State
		{
			get
			{
				if (this.m_endTime == 0f)
				{
					return TouchLongClickElement.EState.STAGE_1;
				}
				if (this.m_startTime < this.m_endTime)
				{
					return TouchLongClickElement.EState.STAGE_2;
				}
				return TouchLongClickElement.EState.STAGE_3;
			}
		}

		protected JobResponse ProcessDown()
		{
			this.m_startTime = Time.time;
			this.m_endTime = this.m_startTime + this.Duration;
			Component elementById = JobRequest.GetElementById(this.Id);
			PointerEventData pointerEventData = new PointerEventData(EventSystem.current);
			PointerEventData pointerEventData2 = pointerEventData;
			Vector2 vector = new Vector2(this.X, this.Y);
			pointerEventData.pressPosition = vector;
			pointerEventData2.position = vector;
			ExecuteEvents.Execute<IPointerDownHandler>(elementById.gameObject, pointerEventData, ExecuteEvents.pointerDownHandler);
			return null;
		}

		protected JobResponse ProcessWait()
		{
			return null;
		}

		protected JobResponse ProcessUp()
		{
			this.m_startTime = 0f;
			this.m_endTime = 0f;
			Component elementById = JobRequest.GetElementById(this.Id);
			PointerEventData pointerEventData = new PointerEventData(EventSystem.current);
			PointerEventData pointerEventData2 = pointerEventData;
			Vector2 vector = new Vector2(this.X, this.Y);
			pointerEventData.pressPosition = vector;
			pointerEventData2.position = vector;
			ExecuteEvents.Execute<IPointerUpHandler>(elementById.gameObject, pointerEventData, ExecuteEvents.pointerUpHandler);
			return new StringResponse();
		}

		public override JobResponse Process()
		{
			if (this.State == TouchLongClickElement.EState.STAGE_1)
			{
				return this.ProcessDown();
			}
			if (this.State == TouchLongClickElement.EState.STAGE_2)
			{
				return this.ProcessWait();
			}
			return this.ProcessUp();
		}

		protected float m_endTime;

		protected float m_startTime;

		protected enum EState
		{
			STAGE_1,
			STAGE_2,
			STAGE_3
		}
	}
}
